package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QualityTest;
import com.ruoyi.system.service.IQualityTestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 质检管理Controller
 * 
 * @author GGJ
 * @date 2024-05-20
 */
@RestController
@RequestMapping("/system/test")
public class QualityTestController extends BaseController
{
    @Autowired
    private IQualityTestService qualityTestService;

    /**
     * 查询质检管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:test:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualityTest qualityTest)
    {
        startPage();
        List<QualityTest> list = qualityTestService.selectQualityTestList(qualityTest);
        return getDataTable(list);
    }

    /**
     * 导出质检管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:test:export')")
    @Log(title = "质检管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityTest qualityTest)
    {
        List<QualityTest> list = qualityTestService.selectQualityTestList(qualityTest);
        ExcelUtil<QualityTest> util = new ExcelUtil<QualityTest>(QualityTest.class);
        util.exportExcel(response, list, "质检管理数据");
    }

    /**
     * 获取质检管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:test:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(qualityTestService.selectQualityTestById(id));
    }

    /**
     * 新增质检管理
     */
    @PreAuthorize("@ss.hasPermi('system:test:add')")
    @Log(title = "质检管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityTest qualityTest)
    {
        return toAjax(qualityTestService.insertQualityTest(qualityTest));
    }

    /**
     * 修改质检管理
     */
    @PreAuthorize("@ss.hasPermi('system:test:edit')")
    @Log(title = "质检管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityTest qualityTest)
    {
        return toAjax(qualityTestService.updateQualityTest(qualityTest));
    }

    /**
     * 删除质检管理
     */
    @PreAuthorize("@ss.hasPermi('system:test:remove')")
    @Log(title = "质检管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(qualityTestService.deleteQualityTestByIds(ids));
    }
}
